package com.hxq.library.controller;

import com.hxq.library.service.IUserService;
import com.hxq.library.service.Impl.UserService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

/**
 * @Author: Ljx
 * @Date: 2021/11/24 19:47
 * @role:
 */
@WebServlet("/register")
public class RegisterServlet extends HttpServlet {

    private static boolean x;
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");
        resp.setContentType("text/html;utf-8");
        String account = req.getParameter("user");
        String password = req.getParameter("pwd");
        if (account==""||password==""){
            req.setAttribute("msg","输入的值不能为空！！！");
            req.getRequestDispatcher("index.jsp").forward(req,resp);
        }else {
            HttpSession session = req.getSession();
            session.setAttribute("account",account);
            IUserService service = new UserService();
            boolean register = service.register(account, password);
            x = register;
            resp.sendRedirect(req.getContextPath()+"panduan.jsp");
        }
    }

    public static boolean rgs() {
        return x;
    }
}
